package chabernac.android.wordbattle.model;

import java.util.List;

import junit.framework.TestCase;

public class WordRasterTest extends TestCase {
  public void testGetNeighbours(){
    WordRaster theRaster = new WordRaster(null, 3, 3, null, null, "nl", null);
    theRaster.setLetter(0, 0, 'a');
    theRaster.setLetter(0, 1, 'b');
    theRaster.setLetter(0, 2, 'c');
    
    theRaster.setLetter(1, 0, 'm');
    theRaster.setLetter(1, 1, 'n');
    theRaster.setLetter(1, 2, 'o');
    
    theRaster.setLetter(2, 0, 'x');
    theRaster.setLetter(2, 1, 'y');
    theRaster.setLetter(2, 2, 'z');
    
    List<Letter> theLetters = theRaster.getNeighbours(theRaster.getLetter(0, 0));
    assertEquals(3, theLetters.size());
    assertTrue(theLetters.contains(theRaster.getLetter(0, 1)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 0)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 1)));
    
    
    theLetters = theRaster.getNeighbours(theRaster.getLetter(0, 2));
    assertEquals(3, theLetters.size());
    assertTrue(theLetters.contains(theRaster.getLetter(0, 1)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 2)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 1)));
    
    theLetters = theRaster.getNeighbours(theRaster.getLetter(2, 2));
    assertEquals(3, theLetters.size());
    assertTrue(theLetters.contains(theRaster.getLetter(2, 1)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 2)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 1)));
    
    theLetters = theRaster.getNeighbours(theRaster.getLetter(2, 0));
    assertEquals(3, theLetters.size());
    assertTrue(theLetters.contains(theRaster.getLetter(2, 1)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 0)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 1)));
    
    theLetters = theRaster.getNeighbours(theRaster.getLetter(1, 1));
    assertEquals(8, theLetters.size());
    assertTrue(theLetters.contains(theRaster.getLetter(0, 0)));
    assertTrue(theLetters.contains(theRaster.getLetter(0, 1)));
    assertTrue(theLetters.contains(theRaster.getLetter(0, 2)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 0)));
    assertTrue(theLetters.contains(theRaster.getLetter(1, 2)));
    assertTrue(theLetters.contains(theRaster.getLetter(2, 0)));
    assertTrue(theLetters.contains(theRaster.getLetter(2, 1)));
    assertTrue(theLetters.contains(theRaster.getLetter(2, 2)));

  }
}
